<template>
  <div>
    <!-- 导航 -->
    <nav-bar class="nav-bar">
      <!-- 返回按钮 -->
      <div slot="left" class="back" @click="back"></div>
      <!-- 其他的按钮 -->
      <div slot="center" class="titles">
        <div
          v-for="(item, index) in titles"
          :key="index"
          class="titles-item"
          :class="{ active: index === currentIndex }"
          @click="titlesItemClick(index)"
        >
          {{ item }}
        </div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
// 导入顶部导航组件
import NavBar from "components/common/navbar/NavBar";
export default {
  name: "DetailNavBar",
  components: {
    NavBar,
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0,
    };
  },
  methods: {
    // 点击切换样式
    titlesItemClick(index) {
      this.currentIndex = index;
      this.$emit("titleClick", index);
    },
    // 点击反回首页
    back() {
      // this.$router.go(-1) 或
      this.$router.back();
    },
  }
};
</script>

<style scoped>
.titles {
  display: flex;
  font-size: 14px;
}
.titles-item {
  flex: 1;
}
.back{
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  background:url(~assets/img/common/back.svg)no-repeat 9px 6px;
  background-size: 30px;
}
.active {
  color: var(--color-high-text);
}
</style>